package common.store.web.controller;

import common.store.admin.dto.Category;
import common.store.admin.service.CategoryService;
import common.store.admin.service.impl.CategoryServiceImpl;
import common.store.web.bean.Product;
import common.store.web.dao.ProductDao;
import common.store.web.service.ProductService;
import common.store.web.service.impl.ProductServiceImpl;

import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/productInfo")
public class productInfoServlet extends HttpServlet{

    private ProductService productService;
    private CategoryService categoryService;
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        categoryService = new CategoryServiceImpl();

        List<Category> categoryList = categoryService.getCategoryList();
        productService = new ProductServiceImpl();
        String pid =req.getParameter("pid");
        Product product=productService.getProductByPid(pid);
        req.setAttribute("categoryList" , categoryList);
        req.setAttribute("product" , product);
        req.getRequestDispatcher("/product_info.jsp").forward(req , resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }
}
